package cn.nacos.common.shiro;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author:ZhouYang
 * @Description:
 * @Date: Created in 2020/8/28 16:51
 * @Modified By：
 */
public class NacosRealm  extends AuthorizingRealm {


    public void setName(){
        super.setName("nacosRealm");
    }


    /**
     * 授权
     * @param principalCollection
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        //1.获取安全数据
//        ProfileResult result = (ProfileResult)principalCollection.getPrimaryPrincipal();
//            principalCollection.getPrimaryPrincipal().var
        //3.构造权限数据，返回值
//        SimpleAuthorizationInfo info = new  SimpleAuthorizationInfo();
//        info.setStringPermissions(null);
//        return null;
        SimpleAuthorizationInfo info = new  SimpleAuthorizationInfo();
        Set<String> set = Sets.newHashSet();
        set.add("sys:user:list");
        info.setStringPermissions(set);
        return info;
    }

    /**
     * 认证
     * @param authenticationToken
     * @return
     * @throws
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
        return null;
    }
}
